<template>
  <div>
    <div><van-nav-bar title="登录"/></div>
    <van-form @submit="onSubmit">
  <van-field
    v-model="info.mobile"
    label="手机号"
    placeholder="请输入手机号"
    :rules="rules.mobile"
  />
  <van-field
    v-model="info.code"
    label="验证码"
    placeholder="请输入验证码"
    :rules="rules.code"
  />246810
  <div style="margin: 16px;">
    <van-button :loading="isLoading"  loading-text="加载中..."  round block  type="info" native-type="submit">登录</van-button>
  </div>
</van-form>
  </div>

</template>

<script>

export default {
  name: 'MyLogin',
  data () {
    return {
      isLoading: false,
      info: {
        mobile: '',
        code: ''
      },
      rules: {
        mobile: [{ required: true, message: '请填入手机号' }, { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' }],
        code: [{ required: true, message: '请填入验证码' }, { pattern: /^\d{6}$/, message: '请填入6位数的验证码' }]
      }
    }
  },
  methods: {
    // 提交触发的事件
    async onSubmit () {
      this.isLoading = true
      this.info.back = this.$route.query.back
      await this.$store.dispatch('user/login', this.info)
      this.isLoading = false
      console.log(this.$route.query.back)
    }
  }
}
</script>

<style></style>
